﻿@{
    ViewBag.Title = "度度圈用户列表";
}
@section headerSection{
    <style>
        #exampleToolbar > .form-group {
            float: left;
            margin: 0;
            margin-left: 5px;
        }
        #exampleToolbar > .form-group {
            float: left;
            margin: 0;
            margin-right: 5px;
            margin-top: 1px;
        }
      .form-group > button {
            margin-top: -2px;
            margin-bottom: 2px;
      }
    </style>
}
<div class="animated fadeInRight">
    <!-- Panel Other -->
    <div class="ibox float-e-margins" style="margin-bottom: 0px;">
        <div class="ibox-content" style="padding: 5px 20px 0px 20px;">
            <div class="row row-lg">
                <div class="col-sm-12 col-sm-leftRight">
                    <!-- Example Toolbar -->
                    <div class="example">
                        <div class="btn-group hidden-xs" id="exampleToolbar" role="group">
                            @{
                                List<string> folderList = (List<string>)ViewBag.elementList;
                                if (folderList.Contains("typeAdd"))
                                {
                                    <button id="typeAdd" type="button" class="btn btn-outline btn-primary">
                                        <i class="glyphicon glyphicon-plus" aria-hidden="true">设为VIP</i>
                                    </button>
                                }
                                if (folderList.Contains("typeDel"))
                                {
                                    <button id="typeDel" type="button" class="btn btn-outline btn-danger">
                                        <i class="glyphicon glyphicon-trash" aria-hidden="true">取消VIP</i>
                                    </button>
                                }
                            }
                            <div class="form-group">
                                <input id="keyword" name="keyword" type="text" class="form-control" placeholder="用户名/登录名/手机号">
                            </div>
                            <div class="form-group" style="margin-left:0;width:160px;margin-top:-1px;">
                                <select id="userStatus" name="userStatus" title="请选择用户状态" data-live-search="true" class="form-control show-tick selectpicker" placeholder="请选择用户状态">
                                    <option value="-1" selected>全部</option>
                                    <option value="0">离线</option>
                                    <option value="1">在线</option>
                                </select>
                            </div>
                            <div class="form-group" style="margin-left:0;width:160px;margin-top:-1px;">
                                <select id="userType" name="userType" title="请选择用户类别" data-live-search="true" class="form-control show-tick selectpicker" placeholder="请选择用户类别">
                                    <option value="-1" selected>全部</option>
                                    <option value="0">普通</option>
                                    <option value="1">VIP</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <button id="btnSearch" class="btn btn-primary" type="button"><i class="fa fa-search"></i>&nbsp;查询</button>
                            </div>
                        </div>
                        <table id="exampleTableToolbar" data-mobile-responsive="true" data-radio="true"></table>
                    </div>
                    <!-- End Example Toolbar -->
                </div>
            </div>
        </div>
    </div>
    <!-- End Panel Other -->
</div>
@section footSection{
    <script>
        var options, $table;
        var partnerManager = {
            initPage: function () {
                partnerManager.initTable();
                partnerManager.bindEvent();
            },
            //初始化Table
            initTable: function() {
                options = {
                    url: ctx + "/VRPartner/InitCircleTable",
                    cutHeight: 5,
                    toolbar: "#exampleToolbar",
                    queryParams: function(params) {
                        params = {
                            //页面大小  
                            rows: params.limit,
                            //第几页
                            page: params.offset / params.limit + 1,
                            keyword: $('#keyword').val(),
                            user_status: $('#userStatus').val(),
                            user_type: $('#userType').val()
                        }
                        return params;
                    },
                    columns: [
                        {
                            radio: true
                        }, {
                            field: '', //第一列序号
                            title: '序号',
                            align: 'center',
                            width: 50,
                            formatter: function(value, row, index) {
                                return index + 1;
                            }
                        }, {
                            field: 'user_type',
                            title: 'VIP',
                            align: 'center',
                            formatter: function (value, row, index) {
                                return value === 1 ? "是" : "否";
                            }
                        }, {
                            field: 'user_status',
                            title: '登录状态',
                            align: 'center',
                            formatter: function (value, row, index) {
                                return value === 1 ? "在线" : "离线";
                            }
                        }, {
                            field: 'login_time',
                            title: '最近登录',
                            align: 'center'
                        }, {
                            field: 'login_name',
                            title: '登录名',
                            align: 'center'
                        }, {
                            field: 'user_name',
                            title: '用户名',
                            align: 'center'
                        },{
                            field: 'du_name',
                            title: '真实姓名',
                            align: 'center'
                        }, {
                            field: 'user_phone',
                            title: '电话号码',
                            align: 'center'
                        }, {
                            field: 'address',
                            title: '所在地',
                            align: 'center'
                        }, {
                            field: 'du_prof',
                            title: '职业',
                            align: 'center'
                        }, {
                            field: 'du_school',
                            title: '毕业学校',
                            align: 'center'
                        }, {
                            field: 'du_hometown',
                            title: '籍贯',
                            align: 'center'
                        }, {
                            field: 'du_sex',
                            title: '性别',
                            align: 'center',
                            formatter: function (value, row, index) {
                                if (value === 1)
                                    return "男";
                                else if (value === 2)
                                    return "女";
                                return "保密";
                            }
                        }, {
                            field: 'du_birthday',
                            title: '年龄',
                            align: 'center'
                        }, {
                            field: 'create_date',
                            title: '注册时间',
                            align: 'center'
                        }]
                }
                $table = tableHelper.initTable("exampleTableToolbar", options);
            },
            //绑定事件
            bindEvent: function() {
                //查询
                $('#btnSearch').click(function () {
                    $table.bootstrapTable('refresh', options);
                });
                //设为VIP
                $('#typeAdd').on('click', function () {
                    partnerManager.resetUserType(1);
                });
                //取消VIP
                $('#typeDel').on('click', function () {
                    partnerManager.resetUserType(0);
                });
            },
            resetUserType: function (userType) {
                //获取选中行数据
                var row = partnerManager.selections(true);
                if (!row)
                    return false;
                var userid = new Array();
                $.each(row, function (index, item) {
                    userid.push(item.user_id);
                });
                var index = layer.msg("VIP类别设置中...", { icon: 6, time: 6000 });
                $.ajax({
                    url: ctx + '/VRPartner/EditUserType',
                    type: "post",
                    cache: false,
                    async: false,
                    data: { "user_type": userType, "userid": userid.join(',') },
                    dataType: 'json',
                    success: function (result) {
                        if (index)
                            layer.close(index);
                        if (result.Statu === 0) {
                            layer.msg("用户类别设置成功！", { icon: 6 });
                            $table.bootstrapTable('refresh', options);
                        }                          
                        else
                            layer.alert(result.msg);
                    },
                    error: function () {
                        if (index)
                            layer.close(index);
                        layer.msg('数据异常~', { icon: 5 });
                    }
                });
            },
            //获取选中行数据
            selections: function (isAll) {
                var row = $table.bootstrapTable('getSelections');
                if (!row || row.length === 0) {
                    layer.msg("数据为空或未选中记录行~", { icon: 5 });
                    return false;
                }
                if (isAll)
                    return row;
                if (row.length > 1) {
                    layer.msg("当前操作不支持多选，请选择一行再操作！", { icon: 5 });
                    return false;
                }
                return row[0];
            }
        }
        $(function() {
            partnerManager.initPage();
        });
    </script>

}